package com.hellomvp.client.ui;

import com.hellomvp.client.ClientFactory;
import com.hellomvp.client.place.HelloPlace;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

public class TopPanel extends Composite {
	private ClientFactory clientFactory;
	@UiField Button but1;
	@UiField Button but2;
	
	private static TopPanelUiBinder uiBinder = GWT
			.create(TopPanelUiBinder.class);

	interface TopPanelUiBinder extends UiBinder<Widget, TopPanel> {
	}

	public TopPanel() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@UiHandler("but1")
	void onBut1Click(ClickEvent event) {
		if(clientFactory != null) {
			clientFactory.getPlaceController().goTo(new HelloPlace("World!"));
		}
	}
	
	@UiHandler("but2")
	void onBut2Click(ClickEvent event) {
		clientFactory.getPlaceController().goTo(new HelloPlace("Friend!"));
	}
	
	public void setClientFactory(ClientFactory cf) {
		clientFactory = cf;
	}
}
